home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 21 / CU Amiga Magazine's Super CD-ROM 21 (1998)(EMAP Images)(GB)[!][issue 1998-04].iso / CUCD / Magazine / C_Tutorial / Part-9 / wb0 / toolwin.c < prev    next >
C/C++ Source or Header  |  1997-10-27  |  2KB  |  80 lines

  1. #include "toolwin.h"
  2. #include "gadgets.h"
  3. #include "menu.h"
  4. #include "screen.h"
  5.  
  6. #include<intuition/screens.h>
  7.  
  8. #include<stdio.h>
  9.  
  10. #include<clib/gadtools_protos.h>
  11. #include<clib/intuition_protos.h>
  12.  
  13. /* Global record of our tool window */
  14. struct Window* toolwin = NULL;
  15.  
  16. int openToolWin()
  17. {
  18.     /* Extra protection -- only open if not already open */
  19.     if(toolwin == NULL)
  20.     {
  21.         struct Screen* scr = getScreen();
  22.         struct Menu* menu = getMenuStrip();
  23.         /* The minimal height of our tool window */
  24.         int h = gadgetHeight() + scr->WBorTop + (scr->Font->ta_YSize + 1) + scr->WBorBottom;
  25.         /* Open our tool window */
  26.         if(toolwin = OpenWindowTags(NULL,
  27.                                                                 WA_Left,                    0,
  28.                                                                 WA_Top,                        scr->Height - h,
  29.                                                                 /* Make the window sit in the bottom of the screen */
  30.                                                                 WA_Width,                    scr->Width,
  31.                                                                 WA_Height,                h,
  32.                                                                 WA_Flags,                    WFLG_CLOSEGADGET | WFLG_DRAGBAR,
  33.                                                                 WA_IDCMP,                    IDCMP_CLOSEWINDOW | BUTTONIDCMP | IDCMP_REFRESHWINDOW | IDCMP_MENUPICK,
  34.                                                                 WA_Gadgets,                getGadgets(),
  35.                                                                 WA_CustomScreen,    scr,
  36.                                                                 WA_Title,                    "Tools",
  37.                                                                 TAG_DONE,                    0))
  38.         {
  39.             /* Attach menu strip to tool window, as well */
  40.             if(SetMenuStrip(toolwin, menu))
  41.             {
  42.                 /* Let GadTools refresh its bits of the tool window */
  43.                 GT_RefreshWindow(toolwin, NULL);
  44.                 return TRUE;
  45.             }
  46.             else
  47.                 printf("Error: could not attach menus to tool window\n");
  48.         }
  49.         else
  50.             printf("Error: could not open tool window\n");
  51.     }
  52.     else
  53.     {
  54.         printf("Warning: tool window already open\n");
  55.         /* Only a warning, so don't return NULL */
  56.         return TRUE;
  57.     }
  58.     return FALSE;
  59. }
  60.  
  61. void closeToolWin()
  62. {
  63.     if(toolwin)
  64.     {
  65.         ClearMenuStrip(toolwin);
  66.         CloseWindow(toolwin);
  67.         toolwin = NULL;
  68.     }
  69. }
  70.  
  71. struct Window* getToolWin()
  72. {
  73.     return toolwin;
  74. }
  75.  
  76. ULONG getToolSig()
  77. {
  78.     return toolwin ? 1L << toolwin->UserPort->mp_SigBit : 0L;
  79. }    
  80.